<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateOrderAddressesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('order_addresses')) {
            Schema::create('order_addresses', function (Blueprint $table) {
                $table->id();
                $table->integer('user_id')->comment('用户ID');
                $table->string('name')->comment('联系人姓名');
                $table->string('phone')->comment('联系人电话');
                $table->string('province')->comment('省');
                $table->string('city')->comment('市');
                $table->string('area')->comment('区');
                $table->string('address')->comment('详细地址');
                $table->enum('is_default', ['yes', 'no'])->default('no')->comment('是否默认收货地址,no:否,yes:是');
                $table->enum('status', ['normal', 'ban'])->default('normal')->comment('状态,ban:禁用,normal:正常');
                $table->string('label')->nullable()->comment('标签');
                $table->softDeletes();
                $table->timestamps();
                $table->index('user_id');
            });
            DB::statement("ALTER TABLE `order_addresses` comment '用户收货地址表'");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order_addresses');
    }
}
